<?php
$parentCaption = BUtils::T('offers_lbl');
$caption = BUtils::T('offers_list_lbl');
$this->pageTitle = $caption;

$this->breadcrumbs = array(
	$parentCaption => array('index'),
	$caption,
);

//list admin
$admin_list = array();
$connection = Yii::app()->db;
$command = $connection->createCommand('SELECT id, name FROM tbl_sys_admin_account WHERE status=0 ORDER BY name');
$admins = $command->queryAll(true);
$connection->active = false;
foreach ($admins as $sys) {
	$admin_list[(int)$sys['id']] = $sys['name'];
}

$all_lbl = BUtils::T('all_op_lbl');

//get url_offer_img
if (!empty($model[0])) {
$url_offer_img = BUtils::GetOfferPictureUrl(str_replace('thumb_', '', $model[0]['url_offer_img']));
} else $url_offer_img = '';
?>
<div class="page-header position-relative">
	<h1>
		<?php echo $parentCaption; ?>
		<small>
			<i class="icon-double-angle-right"></i>
			<?php echo $caption; ?>
		</small>
	</h1>
</div><!--/.page-header-->

<div class="row-fluid">
	<div class="row-fluid">
		<div class="span12">
			<div class="widget-box transparent">
				<div class="widget-header">
					<h3 class="lighter blue"><?php echo $caption; ?></h3>
					<div class="widget-toolbar">
						<a href="<?php echo Yii::app()->createUrl('/tools/merchant'); ?>">
							<i class="icon-edit blue"></i>
							<span>Create offer from merchants</span>
						</a>
					</div>
				</div>
				<div class="widget-body">
					<div class="widget-body-inner">
					<div class="widget-main no-padding">
						<div class="dataTables_wrapper">
<div class="row-fluid no-border">
	<div class="span12">
		<div class="dataTables_paginate" style="padding-right:8px;">
<?php
echo CHtml::form(Yii::app()->createUrl('/tools/offer/list'), 'post', array('id'=>'search_form', 'style'=>'margin-bottom:8px;'));
echo CHtml::textField('q', Yii::app()->request->getQuery('q'), array('style'=>'width:35%', 'placeholder'=>'Offer content, store name, address or neighborhoods?'));
echo CHtml::dropDownList('id_admin', '', $admin_list, array('empty'=>'All Editors', 'style'=>'width:auto;'));
echo CHtml::dropDownList('filter_status', '', BUtils::SpecialStatus(), array('empty'=>$all_lbl, 'style'=>'width:auto;'));
echo CHtml::dropDownList('filter_date', '', BUtils::SpecialValidStatus(), array('empty'=>$all_lbl, 'style'=>'width:auto;'));
echo CHtml::ajaxSubmitButton(BUtils::T('search_btn'), null, array('beforeSend'=>'beforeSend', 'success'=>'success'), array('class'=>'btn btn-blue'));
echo CHtml::endForm();
?>
		</div>
	</div>
</div>
						</div>

<div class="mobile">
	<div id="loading-bar" style="text-align:center; margin:20px 0;">
		<img src="<?php echo Yii::app()->baseUrl; ?>/img/ajax-loaders/ajax-loader-4.gif" />
	</div>
	<div id="special-list"></div>
</div>
						
					</div>
					</div>
				</div>
			</div><!-- end of widget-box -->
			
		</div>
	</div>
</div>
<script type="text/javascript">
$(function() {
	$.ajax({
		'beforeSend':beforeSend, 'success':success,
		'type':'POST', 'url':location.href, 'data':$('#search_form').serialize()
	});
	
	$('.special_counts a.label').click(function(){
		$('#search_form option').removeAttr('selected');
		var i = $(this).data('index');//find option index
		$('#filter_date option').eq(i).attr('selected', 'selected').trigger('change');
	});
	$('#search_form select').change(function(){
		$.ajax({
			'beforeSend':beforeSend, 'success':success,
			'type':'POST', 'url':location.href, 'data':$('#search_form').serialize()
		});
	});
});
function beforeSend() {
	$("#loading-bar").show();
	$("#special-list").html('');
}
function success(html) {
	$("#loading-bar").hide();
	$("#special-list").html(html);
}
</script>